const state = {
  role: {
    roleInfoList: [],
    index: -1
  }
};

const mutations = {
  setRoleInfos: (state, payLoad) => {
    if (payLoad instanceof Array) {
      state.role.roleInfoList = payLoad;
    } else {
      state.role.index = payLoad;
    }
  }
};

const actions = {
  setRoleInfoAsync: ({ commit }, payload) => {
    commit('setRoleInfos', payload);
  }
};

const getters = {
  roleNow: state => {
    return state.role.roleInfoList[state.role.index];
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};
